// electron
import {ipcMain} from 'electron';

// const
import {
    IPC_SQLITE_DELETE_GROUP_DATA,
    IPC_SQLITE_INSERT_GROUP_DATA,
    IPC_SQLITE_SELECT_GROUP_DATA,
    IPC_SQLITE_UPDATE_GROUP_DATA,
} from '../../constant.ts';
import {delGroup, insertGroup, listGroup, updateGroup} from "./sql-main.ts";

// sqlite

/**
 * SQLiteIPC
 */
export const SQLiteIPC = () => {

    // ipc sqlite insert data
    ipcMain.handle(IPC_SQLITE_INSERT_GROUP_DATA, async (event, ...args) => {
        console.log(`IPC_SQLITE_INSERT_GROUP_DATA  args : ${args}`);
        return await insertGroup(...args);
    });

    // ipc sqlite delete data
    ipcMain.handle(IPC_SQLITE_DELETE_GROUP_DATA, async (event, args) => {
        console.log(`IPC_SQLITE_DELETE_GROUP_DATA  args : ${args}`);
        return await delGroup(args);
    });


    // ipc sqlite update data
    ipcMain.handle(IPC_SQLITE_UPDATE_GROUP_DATA, async (event, ...args) => {
        console.log(`IPC_SQLITE_UPDATE_GROUP_DATA  args : ${args}`);
        return await updateGroup(...args);
    });

    // ipc sqlite select data
    ipcMain.handle(IPC_SQLITE_SELECT_GROUP_DATA, async (event, args) => {
        console.log(`IPC_SQLITE_SELECT_GROUP_DATA  args : ${args}`);
        return await listGroup();
    });

};
